using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Commons;
using WP.Controls;
using WP.DB;

namespace WP.Modules
{
    public partial class frmHighCredits : System.Windows.Forms.Form
    {
        public frmHighCredits()
        {
            InitializeComponent();
        }

        public void ShowHighCredits(DBAccess dBAccess, string strCustNo)
        {
            int i = 0;
            int iNumLenth = 0;
            string strSql = string.Empty;
            DateTime dateCurSt, dtTemp;

            DataRow drTable;
            Label[] ArrlblHighCredits = new Label[36];
            TextBox[] ArrtxtHighCredits = new TextBox[36];

            #region InitArrControl
            foreach (Control con in this.Controls)
            {
                if (con.Name.Length == 15) //"lblHighCredits0", "txtHighCredits0"
                    iNumLenth = 1;
                else
                    iNumLenth = 2;

                i = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - iNumLenth));
                if (con.GetType().Name == "Label")
                {
                    if (con.Name.Substring(0, con.Name.Length - iNumLenth) == "lblHighCredits")
                    {
                        ArrlblHighCredits[i] = con as Label;
                    }
                }
                else if (con.GetType().Name == "TextBox")
                {
                    if (con.Name.Substring(0, con.Name.Length - iNumLenth) == "txtHighCredits")
                    {
                        ArrtxtHighCredits[i] = con as TextBox;
                    }
                }
            }
            #endregion

            #region set high credit lables
            dateCurSt = CvtFunc.ToDateTime(DataFunctions.GetPrdInfo(SystemModules.AR, PeriodRange.PeriodCur, PeriodOption.StPrdDate));
            for (i = 0; i <= 35; i++)
            {
                dtTemp = dateCurSt.AddMonths(-i);
                ArrlblHighCredits[i].Text = dtTemp.ToString("MM/yyyy");
            }
            #endregion

            #region set high credit textboxs
            strSql = "Select HighCredit01";
            for (i = 2; i <= 36; i++)
            {
                strSql += ",HighCredit" + string.Format("{0:00}", i);
            }
            strSql += " From arCustTotals Where CustNo='" + strCustNo + "'";
            drTable = dBAccess.GetDataFirstRow(strSql);

            if (drTable == null)
            {
                for (i = 0; i <= 35; i++)
                {
                    ArrtxtHighCredits[i].Text = "0.00";
                }
            }
            else
            {
                for (i = 0; i <= 35; i++)
                {
                    ArrtxtHighCredits[i].Text = BaseFunctions.FormatNumeric(drTable["HighCredit" + string.Format("{0:00}", i + 1)].ToString(), "NS.2");
                }
            }
            #endregion

        }

    }
}